﻿using System;
using System.Windows;
using System.Windows.Threading;

namespace QSDesigner.Windows
{
    /// <summary>
    /// Interaction logic for CheckerWindow.xaml
    /// </summary>

    public partial class CheckerWindow : Window, IDesignerWindow
    {
        public DesignerItem Item { get; set; }

        //private readonly DispatcherTimer _dispatcherTimer;
        public CheckerWindow()
        {
            InitializeComponent();

            /*_dispatcherTimer = new DispatcherTimer();
            _dispatcherTimer.Tick += (s, a) =>
                                         {
                                             Action action = UpdateDiagram;
                                             Dispatcher.Invoke(action);
                                         };*/
        }

        /*private void UpdateDiagram()
        {
            var updateHistogramCommand = UpdateHistogramCommand.GetInstance();
            var histogramParams = updateHistogramCommand.execute(new Dictionary<string, object> { { "id", DesignerItemId } });

            if ("NO_DATA" == histogramParams["STATE"].ToString())
            {
            }
            else
            {
                DegreesOfFreedom.Text = histogramParams["DEGREES_OF_FREEDOM"].ToString();

                PearsonCriterion.Text = histogramParams["PEARSON_CRITERION"].ToString();

                Count.Text = histogramParams["COUNT"].ToString();

                var pearsonEmpirPoints =
                    new ObservableCollection<KeyValuePair<double, double>>(
                        (List<KeyValuePair<double, double>>)histogramParams["POINTS"]);


                var pearsonTheorPoints =
                    new ObservableCollection<KeyValuePair<double, double>>(
                        (List<KeyValuePair<double, double>>)histogramParams["THEORETICAL_POINTS"]);

                ((LineSeries)PearsonChart.Series[0]).ItemsSource = pearsonEmpirPoints;
                ((LineSeries)PearsonChart.Series[1]).ItemsSource = pearsonTheorPoints;

                if ("HAVE_CHECKED" == histogramParams["STATE"].ToString())
                {
                    _dispatcherTimer.Stop();
                }
            }
        }*/

        private void StartFetchDataButton_Click(object sender, RoutedEventArgs e)
        {

           /* Action action = () =>
                                {
                                    var checkersresourceDictionary = new ResourceDictionary
            {
                Source =
                    new Uri(
                    "/QSDesigner;component/Resources/Properties/Checkers' Properties/CheckersProperties.xaml",
                    UriKind.RelativeOrAbsolute)
            };


                                    var contentControl = (ContentControl)FindName("CWProperties");

                                    if (contentControl != null)
                                        contentControl.Content = checkersresourceDictionary["CheckersProperties"];

                                    var currentBlock = BlockController.GetInstance()[DesignerItemId];

                                    if (contentControl != null)
                                    {
                                        var groupBox = contentControl.Content as GroupBox;

                                        if (groupBox != null)
                                        {
                                            groupBox.DataContext = currentBlock;

                                            var stackPanel = new StackPanel();

                                            foreach (var c in LogicalTreeHelper.GetChildren(groupBox))
                                            {
                                                if (c is StackPanel)
                                                {
                                                    stackPanel = c as StackPanel;
                                                    break;
                                                }
                                            }
                                            var count = VisualTreeHelper.GetChildrenCount(stackPanel);
                                            for (int i = 0; i < count; i++)
                                            {
                                                var childVisual = (Visual)VisualTreeHelper.GetChild(stackPanel, i);
                                                if (childVisual is Grid)
                                                {
                                                    var grid = (Grid)childVisual;
                                                    grid.Visibility = grid.Name == currentBlock.Type.ToString()
                                                                          ? Visibility.Visible
                                                                          : Visibility.Collapsed;
                                                }
                                            }
                                        }
                                    }
                                };

            Dispatcher.CurrentDispatcher.Invoke(action);*/
            
            // Set the Interval
            //_dispatcherTimer.Interval = new TimeSpan(0, 0, 1);

            // Start the timer
            //_dispatcherTimer.Start();

        }

        private void StopFetchDataButton_Click(object sender, RoutedEventArgs e)
        {
            // Stop the timer
            //_dispatcherTimer.Stop();

            //busyIndicator.IsBusy = false;
        }

        
    }
}
